package md.lanjing.com.module_mine.ui.activity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;


import com.lxh.baselibray.mvp.MvpActivity;
import com.lxh.baselibray.util.ObjectUtils;
import com.lxh.baselibray.util.RegexUtils;
import com.lxh.baselibray.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

import com.lxh.baselibray.constant.Constant;

import md.lanjing.com.module_mine.R;
import md.lanjing.com.module_mine.R2;
import md.lanjing.com.module_mine.contact.ModifyLoginPwdContact;
import md.lanjing.com.module_mine.bean.ModifyLoginPwdResponse;
import retrofit2.Response;

/**
 * 修改登录密码
 */
public class ModifyLoginPwdActivity extends MvpActivity<ModifyLoginPwdContact.ModifyLoginPwdPresent> implements ModifyLoginPwdContact.IModifyLoginPwdView {
    @BindView(R2.id.et_current_pwd)
    EditText etCurrentPwd;
    @BindView(R2.id.et_new_pwd)
    EditText etNewPwd;
    @BindView(R2.id.btn_confirm_modify)
    Button btnConfirmModify;



    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_modify_login_pwd;
    }





    @OnClick(R2.id.btn_confirm_modify)
    public void onViewClicked() {
        String oldPwd = etCurrentPwd.getText().toString();
        String newPwd = etNewPwd.getText().toString();
        if (ObjectUtils.isEmpty(oldPwd)) {
            ToastUtils.showLongToast(context, "旧密码不能为空");
            return;
        }
        if (ObjectUtils.isEmpty(newPwd)) {
            ToastUtils.showLongToast(context, "新密码不能为空");
            return;
        }
        if (!RegexUtils.isLoginPwd(newPwd)){
            ToastUtils.showLongToast(context,getString(R.string.login_pwd_regex));
            return;
        }
        showLoadingDialog();
        mPresent.modifyLoginPwd(context,oldPwd,newPwd);
    }

    @Override
    public void getModifyLoginPwdData(Response<ModifyLoginPwdResponse> response) {
        dismissLoadingDialog();
        if (response.body().getCode()== Constant.SUCCESS_CODE){
            ToastUtils.showLongToast(context,"修改密码成功");
            finish();
        }else {
            ToastUtils.showLongToast(context,response.body().getMsg());
        }
    }

    @Override
    protected ModifyLoginPwdContact.ModifyLoginPwdPresent createPresent() {
        return new ModifyLoginPwdContact.ModifyLoginPwdPresent();
    }
}
